/**
 * Created by udi on 2016/11/28.
 */


require(["jv", "vue", "mui", "pop"], function () {
  var Vue = require("vue");

  Vue.config.ignoredElements = ["kv", "k", "v"];

  if (!location.map.token) {
    jv.setToken();
  }

  var PaymentStatusEnum = jv.enumer({
    unpaid: "未支付",
    paid: "已支付"
  });


  var bindVue = function (data) {
    var vm = jv.vm = new Vue({
      el: '#app',
      data: data,
      computed: {},
      methods: {
        getIfUnpaid: function(){
          return this.payment_status == "unpaid";
        },
        getPaymentStatus: function (status) {
          return PaymentStatusEnum.getData(status);
        },
        pay: function (ev) {
          if (window.android && window.android.pay) {
            window.android.pay(this.id);
          }
          else {
            alert("找不到支付接口！");
          }
        },
        cancel: function (ev) {
          var self = this;
          var btnArray = ['否', '是'];
          mui.confirm('确认要取消该订单吗？', "", btnArray, function (e) {
            if (!e.index) {
              return;
            }
            jv.post("/wuye/order/setCancel", {orderId: self.id}, function (res) {
              jv.vm.$data.status = "cancelled";
            });
          });
        },
        getTime: function (dt) {
          dt = new Date(dt);
          return dt.toString("yyyy-MM-dd HH:mm");
        }
      }
    });
  }

  jv.post("/fee/detail", {orderId: location.map.id}, bindVue);

});
